package webExperiment;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

//-----------------------------------------------------
public class MCQuestion extends JPanel {
    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;
    public final static int LONG = 1; // long queston line
    public final static int SHORT = 2; // short question rating are beside

    public static int width = 450;
    public static int questWidthShort = 100;
    public static int heightLong = 60;
    public static int heightTextLong = 30;
    public static int heightShort = 30;

    private JTextArea quest = new JTextArea();
    public JLabel labelLeft = new JLabel();
    public JLabel labelRight = new JLabel();
    private MultipleChoice mc;

    public MCQuestion(int QuestionType, int theNoChoices, Color bgColor) {
	this(QuestionType, theNoChoices, bgColor, 0, false);
    }

    public MCQuestion(int QuestionType, int theNoChoices, Color bgColor,
	    int hGap, boolean createLineBorder) {
	mc = new MultipleChoice(theNoChoices, bgColor, hGap, 0);
	// set muliple choice
	// mc.setSize(new Dimension(160,25));

	this.setBackground(bgColor);
	this.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
	if (createLineBorder)
	    this.setBorder(BorderFactory.createLineBorder(Color.lightGray));

	quest.setEditable(false);
	quest.setLineWrap(true);
	quest.setWrapStyleWord(true);
	quest.setFont(new Font("Arial", Font.BOLD, 12));
	quest.setBackground(bgColor);
	setQuestionColor(Color.BLACK);
	if (QuestionType == LONG) {
	    this.setPreferredSize(new Dimension(width, heightLong));
	    quest.setPreferredSize(new Dimension(width - 10, heightTextLong));
	    // quest.setHorizontalAlignment(SwingConstants.LEFT);
	    quest.setForeground(Color.black);
	    labelLeft.setPreferredSize(new Dimension(100, 20));
	    labelLeft.setHorizontalAlignment(SwingConstants.RIGHT);
	    labelLeft.setForeground(Color.GRAY);
	    labelRight.setPreferredSize(new Dimension(100, 20));
	    labelRight.setHorizontalAlignment(SwingConstants.LEFT);
	    labelRight.setForeground(Color.GRAY);
	} else if (QuestionType == SHORT) {
	    this.setPreferredSize(new Dimension(width, heightShort));
	    quest.setPreferredSize(new Dimension(questWidthShort, 15));
	    // quest.setHorizontalAlignment(SwingConstants.LEFT);
	    quest.setForeground(Color.BLACK);
	    labelLeft.setPreferredSize(new Dimension(60, 20));
	    labelLeft.setHorizontalAlignment(SwingConstants.RIGHT);
	    labelLeft.setForeground(Color.GRAY);
	    // labelLeft.setBorder(BorderFactory.createLineBorder(Color.lightGray));
	    labelRight.setPreferredSize(new Dimension(60, 20));
	    labelRight.setHorizontalAlignment(SwingConstants.LEFT);
	    labelRight.setForeground(Color.GRAY);
	}

	this.add(quest);
	this.add(labelLeft);
	this.add(mc);
	this.add(labelRight);
    }

    public void setQuestionColor(Color fg) {
	quest.setForeground(fg);
    }

    public void writeLabels(String questStr, String choiceLeft,
	    String choiceRight, int preSelectedItem) {
	if (questStr.length() > 0) {
	    quest.setText(questStr);
	    labelLeft.setText(choiceLeft);
	    labelRight.setText(choiceRight);
	    this.setVisible(true);
	} else {
	    setVisible(false);
	}
	mc.reset(preSelectedItem);
    }

    public int getSelectedItem() {
	return mc.getSelectedItem();
    }

    public void addMultipleChoiceActionInterface(
	    MultipleChoiceActionInterface AI) {
	mc.addMultipleChoiceActionInterface(AI);
    }
}// end class (long)
